package de.akabahn.ebd.control;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * @author Peter Eimann
 */
public class EBD_ChooseServiceActivity extends EBD_BaseActivity implements OnClickListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chooseservice);
	}

	@Override
	protected void onStart() {
		super.onStart();
		initializeUser();
		initializeButtons();
	}

	@Override
	protected void onStop() {
		super.onStop();
		getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	}

	@Override
	public void onClick(View v) {
		Intent next = null;

		switch (v.getId()) {
			case R.id.chooseservice_button_handregler:
				next = new Intent(v.getContext(), EBD_HandreglerActivity.class);
				break;
			case R.id.chooseservice_button_dbdweiche:
				next = new Intent(v.getContext(), EBD_DBDWeicheActivity.class);
				break;
			case R.id.chooseservice_button_dbdsignal:
				next = new Intent(v.getContext(), EBD_DBDSignalActivity.class);
				break;
			case R.id.chooseservice_button_settings:
				next = new Intent(this, EBD_PreferenceActivity.class);
				break;
		}

		next.putExtra("de.akabahn.ebd.control.userName", userName);
		next.putExtra("de.akabahn.ebd.control.roleName", role.name());
		next.putExtra("de.akabahn.ebd.control.bhf", bahnhof);
		startActivity(next);
	}

	private void initializeUser() {
		TextView userInfo = (TextView)findViewById(R.id.chooseservice_userInfo);
		userInfo.setText(getResources().getString(R.string.userInfo, userName, role));
	}

	private void initializeButtons() {
		switch (role) {
			case TECHNICIAN: 
				findViewById(R.id.chooseservice_button_handregler).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdweiche).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdsignal).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_settings).setVisibility(View.VISIBLE);
				break;
			case ACTIVE:
				findViewById(R.id.chooseservice_button_handregler).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdweiche).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdsignal).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_settings).setVisibility(View.VISIBLE);
				break;
			case COMMON:
				findViewById(R.id.chooseservice_button_handregler).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdweiche).setVisibility(View.GONE);
				findViewById(R.id.chooseservice_button_dbdsignal).setVisibility(View.GONE);
				findViewById(R.id.chooseservice_button_settings).setVisibility(View.GONE);
				break;
			default:
				findViewById(R.id.chooseservice_button_handregler).setVisibility(View.VISIBLE);
				findViewById(R.id.chooseservice_button_dbdweiche).setVisibility(View.GONE);
				findViewById(R.id.chooseservice_button_dbdsignal).setVisibility(View.GONE);
				findViewById(R.id.chooseservice_button_settings).setVisibility(View.GONE);
				break;
		}

		findViewById(R.id.chooseservice_button_handregler).setOnClickListener(this);
		findViewById(R.id.chooseservice_button_dbdweiche).setOnClickListener(this);
		findViewById(R.id.chooseservice_button_dbdsignal).setOnClickListener(this);
		findViewById(R.id.chooseservice_button_settings).setOnClickListener(this);
	}
}
